const express = require('express')

const mysql = require('../database/index')
const router = express.Router()

//删除文章分类
router.get('/article/deletecate/:id',(req,resp)=>{
//获取多个params参数
// router.get('/article/deletecate/:id/:username',(req,resp)=>{
    // console.log(req.params);
    let sql = `delete form category where id = ${req.params.id}`
    mysql('sql',(err,res)=>{
        if(err) throw err
        if(res.affectedRows!==1) return resp.send({status:1,message:'数据库删除文章分类失败'})
    })
    resp.send('删除文章分类成功')
})


//根据id获取文章
router.get('/article/cates',(req,resp)=>{
    let sql = `select * from category where id = ${req.query.id}; `
    // console.log(req)
    // console.log(sql);
    mysql(sql,(err,res)=>{
        if(err) throw err
        console.log(res);
        console.log(res.affectedRows);
                //results.affectedRows
        // if(res,affectedRow!==1)

        resp.send({status:0,message:'根据id获取文章分类成功',data:res})
    })
})

module.exports=router